﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BUS;
using DTO;


namespace BanSach
{
     
    public partial class frmHDNhap : Form
    {
        public frmHDNhap()
        {
            InitializeComponent();
        }
        int typeSeach;
        private void label7_Click(object sender, EventArgs e)
        {

        }

        private void button5_Click(object sender, EventArgs e)
        {
            dataGridView3.DataSource = Nhap_BUS.LoadHD();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            string mahd = textBox3.Text;
            string masach = textBox4.Text;
            DateTime ngaynhap = DateTime.Parse(textBox5.Text);
            int sl = int.Parse(textBox6.Text);
            float gianhap = float.Parse(textBox1.Text);
            string chietkhau = textBox2.Text;
            string ghichu = textBox9.Text;
            string manv = textBox7.Text;
            string manxb = textBox8.Text;
            Nhap_DTO nhap = new Nhap_DTO(mahd, masach, ngaynhap, sl, gianhap, chietkhau, ghichu, manv, manxb);
            Nhap_BUS.ThemHD(nhap);
            dataGridView3.DataSource = Nhap_BUS.LoadHD();
        }

        private void button6_Click(object sender, EventArgs e)
        {
            string mahd = textBox3.Text;
            string masach = textBox4.Text;
            DateTime ngaynhap = DateTime.Parse(textBox5.Text);
            int sl = int.Parse(textBox6.Text);
            float gianhap = float.Parse(textBox1.Text);
            string chietkhau = textBox2.Text;
            string ghichu = textBox9.Text;
            string manv = textBox7.Text;
            string manxb = textBox8.Text;
            Nhap_DTO sua = new Nhap_DTO(mahd, masach, ngaynhap, sl, gianhap, chietkhau, ghichu, manv, manxb);
            Nhap_BUS.SuaHD(sua);
            dataGridView3.DataSource = Nhap_BUS.LoadHD();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            dataGridView1.DataSource = Nhap_BUS.LoadHD();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            Nhap_BUS.Xoahd(textBox11.Text);
            dataGridView1.DataSource = Nhap_BUS.LoadHD();
        }

        private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {
            if (radioButton1.Checked)
            {
                typeSeach = 1;
            }
        }

        private void radioButton2_CheckedChanged(object sender, EventArgs e)
        {

            if (radioButton2.Checked)
            {
                typeSeach = 2;
            }
        }

        private void radioButton3_CheckedChanged(object sender, EventArgs e)
        {
            if (radioButton3.Checked)
            {
                typeSeach = 3;
            }
        }

        private void radioButton4_CheckedChanged(object sender, EventArgs e)
        {
            if (radioButton4.Checked)
            {
                typeSeach = 4;
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            switch (typeSeach)
            {
                case 1:
                    {
                        dataGridView1.DataSource = Nhap_BUS.TimMaHD(textBox10.Text);
                        break;
                    }
                case 2:
                    {
                        dataGridView1.DataSource = Nhap_BUS.TimMaSach(textBox10.Text);
                        break;
                    }
                case 3:
                    {
                        dataGridView1.DataSource = Nhap_BUS.TimMaNV(textBox10.Text);
                        break;
                    }
                default:
                    {
                        dataGridView1.DataSource = Nhap_BUS.TimMaNXB(textBox10.Text);
                        break;
                    }
            }
        }

        private void button8_Click(object sender, EventArgs e)
        {
            dataGridView2.DataSource = Nhap_BUS.LoadHD();
        }

        private void radioButton8_CheckedChanged(object sender, EventArgs e)
        {
            if (radioButton8.Checked)
            {
                typeSeach = 5;
            }
        }

        private void radioButton7_CheckedChanged(object sender, EventArgs e)
        {
            if (radioButton7.Checked)
            {
                typeSeach = 6;
            }
        }

        private void radioButton6_CheckedChanged(object sender, EventArgs e)
        {
            if (radioButton6.Checked)
            {
                typeSeach = 7;
            }
        }

        private void button9_Click(object sender, EventArgs e)
        {
            switch (typeSeach)
            {
                case 5:
                    {
                        dataGridView2.DataSource = Nhap_BUS.ThongKeTen(textBox12.Text);
                        break;
                    }
                case 6:
                    {
                        dataGridView2.DataSource = Nhap_BUS.ThongKeMaHD(textBox12.Text);
                        break;
                    }
                
                default:
                    {
                        dataGridView2.DataSource = Nhap_BUS.ThongKeTheoNgay(DateTime.Parse(textBox12.Text));
                        break;
                    }
            }
        }

        private void groupBox3_Enter(object sender, EventArgs e)
        {

        }

        private void dataGridView2_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }
    }
}
